package Control;

import boundaryToMatador.GUI;
import Boundary.Text;

/**
 * This is controller class in the dice game.
 * 
 * @author DTU 02312 Gruppe 19
 * 
 */
public class DesktopGame extends BaseGame {
	/**
	 * Start the game.
	 */
	@Override
	public void startGame() {
		super.startGame();
		GUI.showMessage(this.shownText);

		// Start of the actual game. Infinite loop is broken only when someone
		// wins
		while (true) {
			takeTurn();
		}
	}

	@Override
	void writeNextPlayersTurn() {
		this.shownText += Text.getTurn(getPlayer(this.activePlayer).getName());
		GUI.showMessage(this.shownText);
	}

	/**
	 * Writes score and dice values to both GUI and TUI
	 */
	@Override
	void statusTasks() {
		GUI.setDice(this.dieCup.getValueDie1(), this.dieCup.getValueDie2());
		this.shownText = Text.getStatus(this.player1.getName(),
				this.player2.getName(), this.player1.getAccount(),
				this.player2.getAccount(), this.dieCup.getValueDie1(),
				this.dieCup.getValueDie2());
	}

	/**
	 * Prints the name of the current player, along with a message telling that
	 * he has won the game., then waits for input, to make sure the message
	 * stays on the screen. Ends the program when any input is given.
	 */
	@Override
	void winTasks() {
		this.shownText += Text.getWinner(this.currentPlayer.getName(),
				this.currentPlayer.getAccount());
		GUI.showMessage(this.shownText);
		cleanUp();
	}

	/**
	 * Closes the program and cleans up properly.
	 */
	private void cleanUp() {
		GUI.close();
		System.exit(0);
	}
}